package xpn.platform.common.response;

import xpn.platform.common.exception.XpnBusinessException;
import xpn.platform.common.exception.XpnExceptionCodeEnum;

/**
 * 响应构造工具
 * 
 * 
 * @author bobatkm
 * @version 2017年9月2日 下午5:14:21
 */
public class ResponseUtil {
	public static ResponseDTO ok(String message) {
		return new ResponseDTO(message);
	}

	public static Object ok(Object data) {
		return data;
	}

	public static ResponseDTO fail(Integer code, String message) {
		return new ResponseDTO(code, message);
	}

	public static ResponseDTO fail(Integer code, String message, Object data) {
		return new ResponseDTO(code, message, data);
	}

	public static ResponseDTO fail(XpnBusinessException e) {
		return new ResponseDTO(e.getErrorCode(), e.getMessage(), e.getData());
	}

	public static ResponseDTO fail(XpnExceptionCodeEnum exceptionCode, String message) {
		return new ResponseDTO(exceptionCode.getErrorCode(), message);
	}

	public static ResponseDTO fail(XpnExceptionCodeEnum exceptionCode, String message, Object data) {
		return new ResponseDTO(exceptionCode.getErrorCode(), message, data);
	}

	public static ResponseDTO fail(XpnExceptionCodeEnum exceptionCode) {
		return new ResponseDTO(exceptionCode.getErrorCode(), exceptionCode.getErrorMessage());
	}

	public static ResponseDTO fail(XpnExceptionCodeEnum exceptionCode, Object data) {
		return new ResponseDTO(exceptionCode.getErrorCode(), exceptionCode.getErrorMessage(), data);
	}
}